import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.*;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Like
 * Date: 2021-07-14
 * Time: 20:04
 */

public class test {
    private static int count=0;
    private static final Object lock = new Object();
    public static void main(String[] args) throws InterruptedException {

        ExecutorService singleThreadPool = new ThreadPoolExecutor(1, 1,
                0L, TimeUnit.MILLISECONDS,
                new LinkedBlockingQueue<Runnable>(1024), Executors.defaultThreadFactory(), new ThreadPoolExecutor.AbortPolicy());

        new Thread(new testthread(),"even").start();
        new Thread(new testthread(),"odd").start();


    }
    static class testthread implements Runnable{
        @Override
        public void run() {
            while (count<=100){
                synchronized (lock) {
                System.out.println(Thread.currentThread().getName()+":"+count++);
                lock.notify();
                    try {
                        lock.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
//                if (count<=100){
//                    try {
//                        lock.wait();
//                    } catch (InterruptedException e) {
//                        e.printStackTrace();
//                    }
//                }
            }
        }
    }
}}
